<template>
  <div class="app-search-form-container" :class="searchcClassObj">
    <div
      class="collapse-switch"
      :title="showSearch?'收起查询条件':'展开更多查询条件'"
      :class="{active:showSearch}"
      @click="toggleSearch"
    >
      <i class="el-icon-arrow-down" />
    </div>
    <slot />
  </div>
</template>

<script>
export default {
  name: 'CollapseSearch',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
  },
  data () {
    return {
      showSearch: this.visible
    }
  },
  computed: {
    searchcClassObj () {
      if (this.showSearch) {
        return {
          fixedHeight: false
        }
      } else {
        return {
          fixedHeight: true
        }
      }
    }
  },
  methods: {
    toggleSearch () {
      this.showSearch = !this.showSearch
      this.$nextTick(() => {
        this.$emit('update:visible', this.showSearch)
      })
    },
  }
}
</script>

<style scoped lang="scss">
.app-search-form-container{
  position: relative;
  overflow: hidden;
  &.fixedHeight{
    height: 43px;
  }
}
 .collapse-switch {
    cursor: pointer;
    position: absolute;
    right: 0;
    top: 2px;
    width: 30px;
    height: 30px;
    transition: all 0.4s;
    display: inline-block;
    text-align: center;
    line-height: 30px;
    &.active {
        transform: rotateZ(180deg);
    }
    .el-icon-arrow-down {
        font-size: 20px;
    }
}
</style>
